package com.nut.web;

import com.nut.common.Result;
import com.nut.pojo.Order;
import com.nut.pojo.User;
import com.nut.service.OrderService;
import com.nut.service.impl.OrderServiceImpl;
import com.nut.utils.JsonUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class managerOrderServlet extends BaseServlet{
    OrderService orderService = new OrderServiceImpl();
    /**
     * 查询所有订单
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void showAllOrders(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        User login = (User) req.getSession().getAttribute("user");
        if(login == null){
            resp.getWriter().write(JsonUtils.toJson(Result.error().message("login为null")));
        }else {
            List<Order> order = orderService.showAllOrders();
            resp.getWriter().write(JsonUtils.toJson(Result.ok().data("orders", order)));
        }
    }
    /**
     * 发货
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void sendOrder(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        String orderId = req.getParameter("orderId");
        orderService.sendOrder(orderId);
    }
}
